package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Jeanyung
 */
@RestController
@RequestMapping("/nursingLevel")
@Api(tags="护理等级")
public class NursingLevelController {

    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 查询所有护理等级信息
     */
    @GetMapping("/listAll")
    @ApiOperation(value="查询所有护理等级信息")
    public ResponseResult<List<NursingLevelVo>> getAllNursingLevel(){
        List<NursingLevelVo> nursingLevelVos = nursingLevelService.getAllNursingLevel();
        return ResponseResult.success(nursingLevelVos);
    }

    /**
     * 新增护理等级信息
     */
    @PostMapping("/insert")
    @ApiOperation(value="新增护理等级信息")
    public ResponseResult<NursingLevelVo> insertNursingLevel(@RequestBody NursingLevelVo nursingLevel){
        nursingLevelService.insertNursingLevel(nursingLevel);
        return ResponseResult.success(nursingLevel);
    }

    /**
     * 分页查询护理等级信息
     */
    @GetMapping("/listByPage")
    @ApiOperation(value="分页查询护理等级信息")
    public ResponseResult<PageResponse<NursingLevelVo>> pageNursingLevel(
            @ApiParam(value = "页码", required = true) @RequestParam("pageNum") Integer pageNum,
            @ApiParam(value = "每页大小", required = true) @RequestParam("pageSize") Integer pageSize,
            @ApiParam(value = "护理等级名称") @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "护理等级状态") @RequestParam(value = "status", required = false) Integer status) {
        PageResponse<NursingLevelVo> pageResponse = nursingLevelService.listByPage(pageNum, pageSize, name, status);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 根据id查询护理等级信息
     */
    @GetMapping("/{id}")
    @ApiOperation(value="根据id查询护理等级信息")
    public ResponseResult<NursingLevelVo> findById(
            @ApiParam(value = "护理等级ID", required = true) @PathVariable("id") Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 修改护理等级信息
     */
    @PutMapping("/update")
    @ApiOperation(value="修改护理等级信息")
    public ResponseResult<NursingLevelVo> updateNursingLevel(
            @ApiParam(value="护理等级数据",required = true) @RequestBody NursingLevelDto nursingLevel){
        nursingLevelService.updateNursingLevel(nursingLevel);
        return ResponseResult.success(nursingLevel);
    }

    /**
     * 删除护理等级信息
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation(value="删除护理等级信息")
    public ResponseResult deleteNursingLevel(
            @ApiParam(value="护理等级ID",required = true) @PathVariable("id") Long id){
        nursingLevelService.deleteNursingLevel(id);
        return ResponseResult.success();
    }

    /**
     * 启用/禁用护理等级
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value="启用/禁用护理等级")
    public ResponseResult enableOrDisable(
            @ApiParam(value = "护理等级ID", required = true) @PathVariable Long id,
            @ApiParam(value = "护理等级状态", required = true) @PathVariable Integer status) {
        nursingLevelService.enableOrDisable(id, status);
        return ResponseResult.success();
    }
}
